<template>
  <div></div>
</template>

<script>
import { bus } from '@/bus.js';
export default {
  name: '',
  data() {
    return {
      token: '',
      roomInfo: {
        id: '',
        title: '直播间——标题',
        cover: '',
        m3u8Stream: '',
        flvStream: '',
        nOnline: 0,
      },
    };
  },
  methods: {
    userInRoom(token) {
      this.$set(this, 'token', token);
      let params = {
        token: token,
        roomId: this._.get(this.$route, 'query.roomId'),
      };
      return this.$api
        .进入房间(params, {})
        .then((res) => {
          if (res.code === 200) {
            this.$message.success('进入房间，获取直播室相关信息');
            return Promise.resolve(res.data);
          }
        })
        .then((res) => {
          this.$set(this.roomInfo, 'id', res.roomId);
          this.$set(this.roomInfo, 'title', res.roomName);
          this.$set(this.roomInfo, 'cover', res.roomBgImg);
          this.$set(this.roomInfo, 'm3u8Stream', res.videoLiveUrl);
          bus.$emit('获得推流地址', res.videoLiveUrl);
        })
        .catch((err) => {})
        .finally(() => {});
    },
  },
  mounted: function() {
    bus.$on('ws身份认证成功', (wsMsg) => {
      this.$message.success('websocket身份验证通过');
      this.token = wsMsg.token;
      this.userInRoom(wsMsg.token);
    });

    // this.$message.error('error');
  },
};
</script>

<style></style>
